﻿CREATE TABLE [dbo].[admin_RoleInApplications] (
    [RoleId]        UNIQUEIDENTIFIER NOT NULL,
    [ApplicationId] UNIQUEIDENTIFIER NOT NULL,
    [System]        BIT              CONSTRAINT [DF_admin_RoleInApplications_System] DEFAULT ((0)) NULL,
    CONSTRAINT [PK_UserInApplications] PRIMARY KEY CLUSTERED ([RoleId] ASC, [ApplicationId] ASC),
    CONSTRAINT [FK_admin_UserInApplications_aspnet_Applications] FOREIGN KEY ([ApplicationId]) REFERENCES [dbo].[aspnet_Applications] ([ApplicationId]),
    CONSTRAINT [FK_UserInApplications_UserInApplications] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[aspnet_Roles] ([RoleId])
);


GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE TRIGGER [dbo].[admin_AplicationsRoleDelete]
   ON  [dbo].[admin_RoleInApplications]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @deSters smallint
	SET @deSters = 0
	SELECT @deSters = Count(*) from [Deleted] WHERE [System] = 1
	IF @deSters<>0
		GOTO Error1

    GOTO Gata
	Error1:
		RAISERROR ('Aplicatia nu poate fi stears deoarece apartine sistemului!', 16, 1)
		ROLLBACK TRANSACTION
	Gata:

END